home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / AskDLFiles / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  8KB  |  339 lines

  1. /* **** HBBS Door Code****************************************************** */
  2.  
  3. /*
  4.   DoorName
  5.   ========
  6.  
  7.     what the door does
  8.  
  9.   Version
  10.   =======
  11.  
  12.     x.xx, release xx, dd/mm/yyyy
  13.  
  14.   Options
  15.   =======
  16.  
  17.     N_ND->ActiveDoor->SystemOptions
  18.     -------------------------------
  19.  
  20.  
  21.  
  22.     Command Line Arguments
  23.     ----------------------
  24.  
  25.     2  <option>
  26.  
  27.     3  ...
  28.  
  29.     4  .
  30.  
  31.   ToDo
  32.   ====
  33.  
  34.     what you still have to do
  35.  
  36.  
  37.  
  38. */
  39.  
  40. /* **** Includes *********************************************************** */
  41.  
  42. #include <exec/types.h>
  43. #include <exec/memory.h>
  44. #include <dos/dos.h>
  45. #include <clib/exec_protos.h>
  46. #include <clib/dos_protos.h>
  47. #include <clib/alib_protos.h>
  48.  
  49. #include <stdlib.h>
  50. #include <string.h>
  51. #include <stdio.h>
  52. #include <ctype.h>
  53. #include <time.h>
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/types.h>
  58. #include <HBBS/structures.h>
  59. #include <HBBS/hbbscommon_protos.h>
  60. #include <HBBS/hbbscommon_pragmas.h>
  61. #include <HBBS/Hbbsnode_protos.h>
  62. #include <HBBS/Hbbsnode_pragmas.h>
  63. #include <HBBS/release.h>
  64. char *versionstr="$VER: AskDLFiles "RELEASE_STR;
  65.  
  66. /* **** Variables ********************************************************** */
  67.  
  68.  
  69. struct Library *HBBSCommonBase  = NULL;
  70. struct Library *HBBSNodeBase    = NULL;
  71.  
  72. struct BBSGlobalData *BBSGlobal = NULL;
  73. struct NodeData *N_ND           = NULL;
  74. int    N_NodeNum                = -1;
  75. char   outstr[1024];
  76.  
  77. long __stack=16*1024; // increse this in 4k incrments if you suffer from
  78.                       // random/suprious crashings after or during the running
  79.                       // of your door.
  80.  
  81. int    gargc;         // these are just copies of main()'s argc and argv..
  82. char   **gargv;
  83.  
  84. /* **** Functions ********************************************************** */
  85.  
  86.  
  87. #ifdef __SASC
  88. int CXBRK(void) { return(0); }
  89. int _CXBRK(void) { return(0); }
  90. void chkabort(void) {}
  91. #endif
  92.  
  93. static VOID cleanup(ULONG num)
  94. {
  95.   if (HBBSNodeBase)
  96.   {
  97.     HBBS_CleanUpDoor();
  98.     CloseLibrary (HBBSNodeBase);
  99.   }
  100.  
  101.   if (HBBSCommonBase)
  102.   {
  103.     HBBS_CleanUpCommon();
  104.     CloseLibrary (HBBSCommonBase);
  105.   }
  106.  
  107.   if (num) printf("Door Error = %d\n",num);
  108.  
  109.   exit(0);
  110. }
  111.  
  112. static VOID init(char *name)
  113. {
  114.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  115.   {
  116.     cleanup(1);
  117.   }
  118.  
  119.   if (!(HBBS_InitCommon()))
  120.   {
  121.     cleanup(2);
  122.   }
  123.  
  124.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  125.   {
  126.     cleanup(3);
  127.   }
  128.  
  129.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  130.   {
  131.     cleanup(4);
  132.   }
  133.   SetProgramName(name);
  134. }
  135.  
  136. /* **** DoorMain *********************************************************** */
  137.  
  138. /*
  139. void DisplayTaggedFiles( void )
  140. {
  141.   struct TaggedFile *Tag;
  142.   int loop=0;
  143.  
  144.   for (Tag = (struct TaggedFile *)N_ND->TaggedFileList->lh_Head ; Tag->node.ln_Succ ; Tag =(struct TaggedFile*)Tag->node.ln_Succ)
  145.   {
  146.     loop++;
  147.     if (Tag->WarezFile)
  148.     {
  149.       sprintf(outstr,ANSI_FG_CYAN "%d" ANSI_FG_WHITE ") \"" ANSI_FG_GREEN "%-12s" ANSI_FG_WHITE "\", %d, " ANSI_FG_PURPLE "%s\r\n",loop,FilePart(Tag->node.ln_Name),Tag->FileSize,HBBS_ListName(BBSGlobal->ConfList,Tag->ConferenceNum-1)); //-1 cos HBBS_ListName starts at 0.. conf numbers start at 1
  150.     }
  151.     else
  152.     {
  153.       sprintf(outstr,ANSI_FG_CYAN "%d" ANSI_FG_WHITE ") " ANSI_FG_YELLOW "%s\r\n",loop,Tag->node.ln_Name);
  154.     }
  155.  
  156.     DOOR_WriteText(outstr);
  157.   }
  158.   if (loop==0)  DOOR_WriteText(ANSI_FG_CYAN "No Tagged Files!\r\n" ANSI_RESET);
  159.  
  160.   DOOR_WriteText(ANSI_FG_WHITE);
  161. }
  162. */
  163.  
  164. void DoorMain( void )
  165. {
  166.   LONG Bytes=0;
  167.   LONG Files=0;
  168.   V_BIGNUM Mins=0;
  169.   BOOL Done=FALSE,Cancel=FALSE,IsFile;
  170.   struct TaggedFile *node;
  171.   BOOL BytesDisabled=FALSE;
  172.   BOOL FilesDisabled=FALSE;
  173.  
  174.   V_BIGNUM tempnum,loop;
  175.  
  176.   // bytes uploaded * ratio, - bytes downloaded = bytes allowed!
  177.  
  178.   if (N_ND->User.CallData.BytesRatio)
  179.   {
  180.     Bytes=(N_ND->User.CallData.UploadBytes * N_ND->User.CallData.BytesRatio)-N_ND->User.CallData.DownloadBytes;
  181.   }
  182.   else
  183.   {
  184.     BytesDisabled=TRUE;
  185.   }
  186.  
  187.   // work out the files ratio in the same way..
  188.  
  189.   if (N_ND->User.CallData.FilesRatio)
  190.   {
  191.     Files=(N_ND->User.CallData.UploadFiles * N_ND->User.CallData.FilesRatio)-N_ND->User.CallData.DownloadFiles;
  192.   }
  193.   else
  194.   {
  195.     FilesDisabled=TRUE;
  196.   }
  197.  
  198.   // then remove all the bytes and files of the other files that are already tagged
  199.  
  200.   for (node=(struct TaggedFile *)N_ND->TaggedFileList->lh_Head;node->node.ln_Succ;node=(struct TaggedFile *)node->node.ln_Succ)
  201.   {
  202.     if (!BytesDisabled) Bytes-=node->FileSize;
  203.     if (!FilesDisabled) Files--;
  204.   }
  205.  
  206.   if (N_ND->TaggedFiles)
  207.   {
  208.     DOOR_WriteText("You have got these files tagged already..\r\n");
  209. //    DisplayTaggedFiles();
  210.     DOOR_UserDoor("A","L");
  211.   }
  212.  
  213.   while ( ((Bytes>=0) || (BytesDisabled)) && ((Files>=0) || (FilesDisabled)) && (!Done))
  214.   {
  215.     sprintf(outstr,ANSI_RESET "Files Tagged : %ld ,",N_ND->TaggedFiles);
  216.     DOOR_WriteText(outstr);
  217.  
  218.     if (FilesDisabled)
  219.     {
  220.       DOOR_WriteText("Files Disabled ,");
  221.     }
  222.     else
  223.     {
  224.       sprintf(outstr," Files Left %ld ,",Files);
  225.       DOOR_WriteText(outstr);
  226.     }
  227.     if (BytesDisabled)
  228.     {
  229.       DOOR_WriteText("Bytes Disabled ,");
  230.     }
  231.     else
  232.     {
  233.       sprintf(outstr," Bytes Left : %ld ,",Bytes);
  234.       DOOR_WriteText(outstr);
  235.     }
  236.     sprintf(outstr," Mins Left : %ld\r\n\r\n",Mins);
  237.     DOOR_WriteText(outstr);
  238.     DOOR_MenuPrompt("[D]one, [L]ist, [Q]uit, or name of file : ",'D');
  239.     DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_HISTORY,'\0',0,0,NULL);
  240.     if (N_ND->OnlineStatus==OS_ONLINE)
  241.     {
  242.       RemoveSpaces(N_ND->CurrentLine);
  243.       if (N_ND->CurrentLine[0])
  244.       {
  245.         IsFile=FALSE;
  246.         if (N_ND->CurrentLine[1]==0) // an option!
  247.         {
  248.           switch (toupper(N_ND->CurrentLine[0]))
  249.           {
  250.             case 'D':
  251.               Done=TRUE;
  252.               break;
  253.             case 'Q':
  254.               DOOR_WriteText("Quit!\r\n");
  255.               Done=TRUE;
  256.               Cancel=TRUE;
  257.               break;
  258.             case 'L':
  259.               DOOR_UserDoor("A","L");
  260.               break;
  261.             default:
  262.               IsFile=TRUE;
  263.               break;
  264.           }
  265.         }
  266.         else
  267.         {
  268.           IsFile=TRUE;
  269.         }
  270.         if (IsFile)
  271.         {
  272.           DOOR_UserDoor("A",N_ND->CurrentLine);
  273.           if (N_ND->OnlineStatus==OS_ONLINE)
  274.           {
  275.             // how many files did we tag ?
  276.             if (sscanf(N_ND->DoorReturn,"%ld",&tempnum))
  277.             {
  278.               if (tempnum>0)
  279.               {
  280.                 // lots, so check the bytes and files..
  281.                 for (loop=N_ND->TaggedFiles-tempnum;loop<N_ND->TaggedFiles;loop++)
  282.                 {
  283.                   node=(struct TaggedFile *)GetNode(N_ND->TaggedFileList,loop);
  284.                   if (!FilesDisabled) Files--;
  285.                   if (!BytesDisabled) Bytes-=node->FileSize;
  286.                 }
  287.               }
  288.             }
  289.           }
  290.         }
  291.       }
  292.       else
  293.       {
  294.         Done=TRUE;
  295.       }
  296.     }
  297.     if (N_ND->OnlineStatus==OS_OFFLINE)
  298.     {
  299.       Done=TRUE;
  300.       Cancel=TRUE;  // lost carrier!
  301.     }
  302.   }
  303.  
  304.   // user gone over the limit ???
  305.  
  306. //  if ((!Done) && (!Cancel) && (N_ND->OnlineStatus==OS_ONLINE))
  307.   if ( ((Bytes<0) && (!BytesDisabled)) || ((Files<0) && (!FilesDisabled)) && (N_ND->OnlineStatus==OS_ONLINE))
  308.   {
  309.     DOOR_WriteText("Not Enough Byte or File Credits, please untag some files\r\n"
  310.                    "or upload more files!\r\n");
  311.     Cancel=TRUE;
  312.   }
  313.   if (Cancel) DOOR_Return("CANCEL"); else DOOR_Return("OK");
  314. }
  315.  
  316. int main(int argc,char **argv)
  317. {
  318.   gargc=argc;
  319.   gargv=argv;
  320.  
  321.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  322.   {
  323.     printf("Invalid/No Paramaters for door!\n");
  324.     exit (20);
  325.   }
  326.   init("AskDLFiles");
  327.  
  328.   if (BBSGlobal=HBBS_GimmeBBS())
  329.   {
  330.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  331.     {
  332.       DoorMain();
  333.     }
  334.   }
  335.   cleanup(0);
  336. }
  337.  
  338. /* **** End Of File ******************************************************** */
  339.